//////////////////////////////////////////////////////////////////////////////////////////////
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	File			:	"IGameState.h"
//	Authors			:	Jake Castillo,
//	Course:			:	SGP 1306
//	Purpose			:	IGameState is the basic interface for all game states in the game. 
//						Kinda like iRobot, but better and less intelligent.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "../SGD Wrappers/CSGD_DirectInput.h"
#include "../SGD Wrappers/CSGD_XAudio2.h"
#include "../Game Essentials/Game.h"
#include "../Fonts/Font.h"
#include "../SGD Wrappers/CSGD_TextureManager.h"

class IGameState
{
private:
	int moveSFXID;
	int enterSFXID;

	// FPS
	unsigned int			m_unFPS;
	unsigned int			m_unFrames;
	float					m_fFPSTimer;
	bool					m_bShowFPS;

protected:
	Font* font;

public:
	IGameState(void)					
	{
		//moveSFXID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("Resource/Sounds/SFX/Menus/Menu Selection.wav"));
		//enterSFXID	= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("Resource/Sounds/SFX/Menus/Menu Entry.wav"));

		m_fFPSTimer = 0.0f;
		m_unFrames	= 0;
		m_unFPS		= 0;	
		m_bShowFPS	= false;
	}

	virtual ~IGameState(void)					= 0
	{
		//if(moveSFXID != -1)
		//{
		//	CSGD_XAudio2::GetInstance()->SFXUnloadSound(moveSFXID);
		//	moveSFXID = -1;
		//}

		//if(enterSFXID != -1)
		//{
		//	CSGD_XAudio2::GetInstance()->SFXUnloadSound(enterSFXID);
		//	enterSFXID = -1;
		//}
	}

	virtual void Enter ( void )					= 0;
	virtual void Exit  ( void )					= 0;
												
	virtual bool Input ( void )					= 0
	{
		if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_F1))
			m_bShowFPS = !m_bShowFPS;

		return true;
	}

	virtual void Update( float fElapsedTime )	= 0
	{
		// Update the FPS
		m_fFPSTimer += fElapsedTime;
		m_unFrames++;

		if( m_fFPSTimer > 1.0f )	// 1 sec
		{
			m_fFPSTimer = 0.0f;
			m_unFPS		= m_unFrames;
			m_unFrames	= 0;
		}
	}

	virtual void Render( void )					= 0
	{
		if( m_bShowFPS == true )
		{
			Font* f = CGame::GetInstance()->GetMenuFont();

			// Render the FPS
			TOSTRINGSTREAM output;
			output << _T("FPS: ") << m_unFPS;
			f->Draw( output.str().c_str(), 350, 10, 1.0f, 
				D3DCOLOR_ARGB( 255, 255, 0, 255) );
		}
	}

	int GetMove() const		{ return moveSFXID;		}
	int GetEnter() const	{ return enterSFXID;	}

	void PlayMove()
	{
		//if(!CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(moveSFXID))
			CSGD_XAudio2::GetInstance()->SFXPlaySound(moveSFXID);
	}

	void PlayEnter()
	{
		//if(!CSGD_XAudio2::GetInstance()->SFXIsSoundPlaying(enterSFXID))
			CSGD_XAudio2::GetInstance()->SFXPlaySound(enterSFXID);
	}
};